package com.pro.common.modules.service.dependencies.controller;

import com.pro.common.api.enums.EnumSysRole;
import com.pro.common.api.model.ILoginInfo;
import com.pro.common.api.model.auth.IUserOrderClass;
import com.pro.common.api.model.request.pay.OrderResponse;
import com.pro.common.modules.service.dependencies.model.request.IOrderRequest;
import com.pro.common.modules.service.dependencies.service.BaseOrderPayService;
import com.pro.common.modules.service.dependencies.util.IPUtils;
import com.pro.framework.api.util.AssertUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;


//@Tag(name = "订单管理")
//@RestController
//@RequestMapping("/")
public abstract class BaseOrderController<T extends IUserOrderClass, REQ extends IOrderRequest> {

    protected abstract BaseOrderPayService<T, REQ> getService();


//    HttpServletResponse response,
    @Operation(summary = "订单下单")
    @PostMapping("/createOrder")
    public OrderResponse<T> createOrder(
            HttpServletRequest request,
            @Parameter(hidden = true) ILoginInfo loginInfo,
            @RequestBody REQ req) {
        String ip = IPUtils.getIpAddress(request);
//        AssertUtil.isTrue(!EnumSysRole.ANONYMOUS.equals(loginInfo.getSysRole()), "请先登录");
//        AssertUtil.isTrue(EnumSysRole.USER.equals(loginInfo.getSysRole()), "暂无权限");
        return getService().createOrder(loginInfo, req, ip);
    }
}
